home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / include / x11 / xlibnet.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-11  |  7.6 KB  |  275 lines

  1. /* $XConsortium: Xlibnet.h,v 1.18 91/07/23 19:01:27 rws Exp $ */
  2.  
  3. /*
  4. Copyright 1991 Massachusetts Institute of Technology
  5.  
  6. Permission to use, copy, modify, distribute, and sell this software and its
  7. documentation for any purpose is hereby granted without fee, provided that
  8. the above copyright notice appear in all copies and that both that
  9. copyright notice and this permission notice appear in supporting
  10. documentation, and that the name of M.I.T. not be used in advertising or
  11. publicity pertaining to distribution of the software without specific,
  12. written prior permission.  M.I.T. makes no representations about the
  13. suitability of this software for any purpose.  It is provided "as is"
  14. without express or implied warranty.
  15. */
  16. /*
  17.  * Xlibnet.h - Xlib networking include files for UNIX Systems.
  18.  */
  19.  
  20. #ifndef X_UNIX_PATH
  21. #ifdef hpux
  22. #define X_UNIX_PATH "/usr/spool/sockets/X11/"
  23. #define OLD_UNIX_PATH "/tmp/.X11-unix/X"
  24. #else
  25.  
  26. #ifdef MSDOS
  27. #define X_UNIX_PATH "DESQview X Server"
  28. #else
  29. #define X_UNIX_PATH "/tmp/.X11-unix/X"
  30. #endif
  31.  
  32. #endif
  33. #endif /* X_UNIX_PATH */
  34.  
  35. #ifdef STREAMSCONN
  36. #ifdef SYSV
  37. /*
  38.  * UNIX System V Release 3.2
  39.  */
  40. #define BytesReadable(fd,ptr) (_XBytesReadable ((fd), (ptr)))
  41. #define MALLOC_0_RETURNS_NULL
  42. #include <sys/ioctl.h>
  43.  
  44. #endif /* SYSV */
  45. #ifdef SVR4
  46. /*
  47.  * TLI (Streams-based) networking
  48.  */
  49. #define BytesReadable(fd,ptr) (_XBytesReadable ((fd), (ptr)))
  50. #include <sys/uio.h>            /* define struct iovec */
  51.  
  52. #endif /* SVR4 */
  53. #else /* not STREAMSCONN */
  54. /*
  55.  * socket-based systems
  56.  */
  57. #include <netinet/in.h>
  58. #include <sys/ioctl.h>
  59. #include <netdb.h>
  60. #include <sys/uio.h>    /* needed for XlibInt.c */
  61. #ifdef SVR4
  62. #include <sys/filio.h>
  63. #endif
  64.  
  65. #if defined(SYSV386) && defined(SYSV)
  66. #include <net/errno.h>
  67. #include <sys/stropts.h>
  68. #define BytesReadable(fd,ptr) ioctl((fd), I_NREAD, (ptr))
  69. #else
  70. #define BytesReadable(fd, ptr) ioctl ((fd), FIONREAD, (ptr))
  71. #endif
  72.  
  73. #endif /* STREAMSCONN else */
  74.  
  75. /*
  76.  * If your BytesReadable correctly detects broken connections, then
  77.  * you should NOT define XCONN_CHECK_FREQ.
  78.  */
  79. #define XCONN_CHECK_FREQ 256
  80.  
  81. #ifndef X_NOT_POSIX
  82. #ifdef _POSIX_SOURCE
  83. #include <limits.h>
  84. #else
  85. #define _POSIX_SOURCE
  86. #include <limits.h>
  87. #undef _POSIX_SOURCE
  88. #endif
  89. #endif
  90. #ifndef OPEN_MAX
  91. #ifdef SVR4
  92. #define OPEN_MAX 256
  93. #else
  94. #include <sys/param.h>
  95. #ifndef OPEN_MAX
  96. #ifdef NOFILE
  97. #define OPEN_MAX NOFILE
  98. #else
  99. #define OPEN_MAX NOFILES_MAX
  100. #endif
  101. #endif
  102. #endif
  103. #endif
  104.  
  105. #if OPEN_MAX > 256
  106. #undef OPEN_MAX
  107. #define OPEN_MAX 256
  108. #endif
  109.  
  110. #define MSKCNT ((OPEN_MAX + 31) / 32)
  111.  
  112. #if (MSKCNT==1)
  113. #define BITMASK(i) (1 << (i))
  114. #define MASKIDX(i) 0
  115. #endif
  116. #if (MSKCNT>1)
  117. #define BITMASK(i) (1 << ((i) & 31))
  118. #define MASKIDX(i) ((i) >> 5)
  119. #endif
  120.  
  121. #define MASKWORD(buf, i) buf[MASKIDX(i)]
  122. #define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
  123. #define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
  124. #define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
  125.  
  126. #if (MSKCNT==1)
  127. #define COPYBITS(src, dst) dst[0] = src[0]
  128. #define CLEARBITS(buf) buf[0] = 0
  129. #define MASKANDSETBITS(dst, b1, b2) dst[0] = (b1[0] & b2[0])
  130. #define ORBITS(dst, b1, b2) dst[0] = (b1[0] | b2[0])
  131. #define UNSETBITS(dst, b1) (dst[0] &= ~b1[0])
  132. #define _XANYSET(src) (src[0])
  133. #endif
  134. #if (MSKCNT==2)
  135. #define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; }
  136. #define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; }
  137. #define MASKANDSETBITS(dst, b1, b2)  {\
  138.               dst[0] = (b1[0] & b2[0]);\
  139.               dst[1] = (b1[1] & b2[1]); }
  140. #define ORBITS(dst, b1, b2)  {\
  141.               dst[0] = (b1[0] | b2[0]);\
  142.               dst[1] = (b1[1] | b2[1]); }
  143. #define UNSETBITS(dst, b1) {\
  144.               dst[0] &= ~b1[0]; \
  145.               dst[1] &= ~b1[1]; }
  146. #define _XANYSET(src) (src[0] || src[1])
  147. #endif
  148. #if (MSKCNT==3)
  149. #define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; \
  150.                  dst[2] = src[2]; }
  151. #define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; buf[2] = 0; }
  152. #define MASKANDSETBITS(dst, b1, b2)  {\
  153.               dst[0] = (b1[0] & b2[0]);\
  154.               dst[1] = (b1[1] & b2[1]);\
  155.               dst[2] = (b1[2] & b2[2]); }
  156. #define ORBITS(dst, b1, b2)  {\
  157.               dst[0] = (b1[0] | b2[0]);\
  158.               dst[1] = (b1[1] | b2[1]);\
  159.               dst[2] = (b1[2] | b2[2]); }
  160. #define UNSETBITS(dst, b1) {\
  161.               dst[0] &= ~b1[0]; \
  162.               dst[1] &= ~b1[1]; \
  163.               dst[2] &= ~b1[2]; }
  164. #define _XANYSET(src) (src[0] || src[1] || src[2])
  165. #endif
  166. #if (MSKCNT==4)
  167. #define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; \
  168.                dst[2] = src[2]; dst[3] = src[3]
  169. #define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0; buf[3] = 0
  170. #define MASKANDSETBITS(dst, b1, b2)  \
  171.               dst[0] = (b1[0] & b2[0]);\
  172.               dst[1] = (b1[1] & b2[1]);\
  173.               dst[2] = (b1[2] & b2[2]);\
  174.               dst[3] = (b1[3] & b2[3])
  175. #define ORBITS(dst, b1, b2)  \
  176.               dst[0] = (b1[0] | b2[0]);\
  177.               dst[1] = (b1[1] | b2[1]);\
  178.               dst[2] = (b1[2] | b2[2]);\
  179.               dst[3] = (b1[3] | b2[3])
  180. #define UNSETBITS(dst, b1) \
  181.               dst[0] &= ~b1[0]; \
  182.               dst[1] &= ~b1[1]; \
  183.               dst[2] &= ~b1[2]; \
  184.               dst[3] &= ~b1[3]
  185. #define _XANYSET(src) (src[0] || src[1] || src[2] || src[3])
  186. #endif
  187.  
  188. #if (MSKCNT>4)
  189. #define COPYBITS(src, dst) bcopy((char *) src, (char *) dst,\
  190.                  MSKCNT*sizeof(long))
  191. #define CLEARBITS(buf) bzero((char *) buf, MSKCNT*sizeof(long))
  192. #define MASKANDSETBITS(dst, b1, b2)  \
  193.               { int cri;                        \
  194.             for (cri=MSKCNT; --cri>=0; )    \
  195.               dst[cri] = (b1[cri] & b2[cri]); }
  196. #define ORBITS(dst, b1, b2)  \
  197.               { int cri;                        \
  198.               for (cri=MSKCNT; --cri>=0; )      \
  199.               dst[cri] = (b1[cri] | b2[cri]); }
  200. #define UNSETBITS(dst, b1) \
  201.               { int cri;                        \
  202.               for (cri=MSKCNT; --cri>=0; )      \
  203.               dst[cri] &= ~b1[cri];  }
  204. /*
  205.  * If MSKCNT>4, then _XANYSET is a routine defined in XlibInt.c.
  206.  *
  207.  * #define _XANYSET(src) (src[0] || src[1] || src[2] || src[3] || src[4] ...)
  208.  */
  209. #endif
  210.  
  211. /*
  212.  *      ReadvFromServer and WritevToSever use struct iovec, normally found
  213.  *      in Berkeley systems in <sys/uio.h>.  See the readv(2) and writev(2)
  214.  *      manual pages for details.
  215.  *
  216.  *      struct iovec {
  217.  *              caddr_t iov_base;
  218.  *              int iov_len;
  219.  *      };
  220.  */
  221. #if defined(USG) && !defined(CRAY) && !defined(umips) && !defined(MOTOROLA)
  222. struct iovec {
  223.     caddr_t iov_base;
  224.     int iov_len;
  225. };
  226. #endif /* USG */
  227.  
  228.  
  229. #ifdef STREAMSCONN
  230. #include "Xstreams.h"
  231.  
  232. extern char _XsTypeOfStream[];
  233. extern Xstream _XsStream[];
  234.  
  235. #define ReadFromServer(dpy, data, size) \
  236.     (*_XsStream[_XsTypeOfStream[dpy]].ReadFromStream)((dpy), (data), (size), \
  237.                              BUFFERING)
  238. #define WriteToServer(dpy, bufind, size) \
  239.     (*_XsStream[_XsTypeOfStream[dpy]].WriteToStream)((dpy), (bufind), (size))
  240.  
  241. #else /* else not STREAMSCONN */
  242.  
  243. /*
  244.  * bsd can read from sockets directly
  245.  */
  246. #ifdef MSDOS
  247. #define ReadFromServer(dpy, data, size) recv((dpy), (data), (size), (0))
  248. #define WriteToServer(dpy, bufind, size) send((dpy), (bufind), (size), (0))
  249. #else
  250. #define ReadFromServer(dpy, data, size) read((dpy), (data), (size))
  251. #define WriteToServer(dpy, bufind, size) write((dpy), (bufind), (size))
  252. #endif
  253.  
  254. #endif /* STREAMSCONN */
  255.  
  256.  
  257. #ifndef USL_COMPAT
  258. #if !defined(USG) || defined(MOTOROLA)
  259. #if !(defined(SYSV) && defined(SYSV386))
  260. #define _XReadV readv
  261. #endif
  262. #define _XWriteV writev
  263. #endif
  264. #endif /* !USL_COMPAT */
  265.  
  266. #ifdef MSDOS
  267. #undef  _XReadV
  268. #define _XReadV  recvv
  269. #undef  _XWriteV
  270. #define _XWriteV sendv
  271. #endif
  272.  
  273. #define ReadvFromServer(dpy, iov, iovcnt) _XReadV((dpy), (iov), (iovcnt))
  274. #define WritevToServer(dpy, iov, iovcnt) _XWriteV((dpy), (iov), (iovcnt))
  275.